package com.vehicle.controller;
import com.vehicle.bean.Violation;
import com.vehicle.form.ViolationForm;
import com.vehicle.service.ViolationService;
import com.vehicle.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 校园车辆管理系统
 * @since 2023-05-14
 */
@RestController
@RequestMapping("/violation")
public class ViolationController {

    @Autowired
    ViolationService violationService;

    //    添加：添加违规单：carId,以及：违规信息
    @PostMapping("/add")
    public ResultVO addViolation(@RequestBody ViolationForm violationForm){
        return ResultVO.succ(violationService.addVolation(violationForm));
    }

    //    修改: vioId,message
    @PutMapping("/update")
    public ResultVO updateViolationMessage(@RequestBody Violation violation){
        return ResultVO.succ(violationService.updateMessage(violation));
    }

    //  查询：分页查询所有
    @GetMapping("/allList/{page}/{size}")
    public ResultVO getAllViolation(@PathVariable("page") String page,@PathVariable("size") String size){
        return ResultVO.succ(violationService.getAllViolation(Integer.parseInt(page),Integer.parseInt(size)));
    }

    //模糊查询：学校名字
    @GetMapping("/likeList/{message}")
    public ResultVO getLikeViolation(@PathVariable("message") String message){
        return ResultVO.succ(violationService.getLikeViolation(message));
    }

    //修改：将违规单变为已处理
    @PutMapping("/process/{vioId}")
    public ResultVO setProcessed(@PathVariable("vioId") Integer vioId){
        return ResultVO.succ(violationService.updateProcessed(vioId));
    }

    //根据添加的检察员id来查询
    @GetMapping("/getListById/{adminId}")
    public ResultVO getListByAdminId(@PathVariable("adminId") Integer adminId){
//        Integer userId = Integer.parseInt(adminId);
//        System.out.println(userId);
//        System.out.println(adminId);
        return ResultVO.succ(violationService.getListByAdmin(adminId));
//        return ResultVO.succ(violationService.getListByAdmin(adminId));
    }

    //获取指定用户的违规记录
    @GetMapping("/getListByUserId/{userId}")
    public ResultVO getListByUserId(@PathVariable("userId")Integer userId){
        return ResultVO.succ(violationService.getListByUserId(userId));
    }

    @DeleteMapping("/delete/{vioId}")
    public ResultVO deleteViolation(@PathVariable("vioId") Integer vioId){
     return ResultVO.succ(violationService.removeById(vioId));
    }

    @GetMapping("/getMessageByParkingId/{parkingId}")
    public ResultVO getMessageByParkingId(@PathVariable("parkingId") Integer parkingId){
        return ResultVO.succ(violationService.getMessageByParking(parkingId));
    }

    //根据用户id获取用户违规次数
    @GetMapping("/getViolationNumber/{userId}")
    public ResultVO getViolationNumber(@PathVariable("userId") Integer userId){

        return ResultVO.succ(violationService.getNumber(userId));
    }

    //根据用户id获取最后一次违规时间
    @GetMapping("/getViolationTime/{userId}")
    public ResultVO getViolationTime(@PathVariable("userId") Integer userId){

        return ResultVO.succ(violationService.getTime(userId));
    }

}

